home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / docs / hyper / IndexAG.lha / IndexAG / strip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-14  |  1.5 KB  |  61 lines

  1. char *strip(char *string, char *exclude, char mode)  /* This strips a list of characters depending on mode */
  2. {                                                    /* Modifies the buffer directly */
  3.    char *a;
  4.    char *b;
  5.    int match;
  6.    
  7.     switch(mode)
  8.    {
  9.       case 'S':                                   /* strip at the start of the string */
  10.         for(match=0,a=string; *a, !match; a++)
  11.         {
  12.            match=1;
  13.            for(b=exclude; *b; b++)
  14.               if (*a==*b)
  15.               {
  16.                  strcpy(a, a+1);
  17.                  a--;
  18.                  match=0;
  19.               }
  20.         }
  21.         break;
  22.       
  23.       case 'E':                                                         /* strip at the end of the string */
  24.           for(match=0, a=string, a+=strlen(string)-1; *a, !match; a--)
  25.         {
  26.               match =1;
  27.               for(b=exclude; *b && match; b++)
  28.            {
  29.                   if (*a==*b)
  30.               {
  31.                       strcpy(a, a+1);
  32.                       match=0;
  33.               }
  34.            }
  35.         }
  36.           break;
  37.        
  38.      case 'A':                     /* strip all from the string */
  39.         for(a=string; *a; a++)
  40.         {
  41.            for(b=exclude; *b; b++)
  42.               if(*a==*b)
  43.               {
  44.                  strcpy(a, a+1);
  45.                  a--;
  46.               }
  47.         }
  48.         break;
  49.      
  50.      case 'B':                        /* strip both beginning and end only */
  51.         strip(string, exclude, 'S');
  52.         strip(string, exclude, 'E');
  53.         break;
  54.         
  55.      default:
  56.         break;           
  57.    }
  58.  
  59.   return string;
  60. }
  61.